﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.CacheService.CacheProvider;
using A2DFramework.CacheService.Coordinator;
using A2DFramework.CacheService.Configuration;

namespace A2DFramework.CacheService
{
    public class CacheManager
    {
        private static CacheManager manager=null;
        public static CacheManager Instance()
        {
            if(manager==null)
                manager=new CacheManager();
            return manager;
        }

        private Dictionary<string, CacheCore> cacheCores = new Dictionary<string, CacheCore>();
        public CacheCore GetCacheCore(string location)
        {
            CacheCore core = null;
            if(cacheCores.ContainsKey(location))
                return cacheCores[location];

            ICacheCoordinator coordinator = new CacheCoordinator(location);
            Storage storageSetting = CacheConfiguration.Storages[location];
            core = new CacheCore(storageSetting, coordinator);
            cacheCores[location] = core;

            return core;
        }
    }
}
